<?php

/**
 * Celebrio Kernel
 *
 * @copyright  Copyright (c) 2012 Celebrio Software, s.r.o.
 * @package    Kernel
 */
namespace KernelModule\LogsModule\LoggerModule;

use KernelModule\BasePresenter;
use KernelModule\LogsModule\LoggerModule\LogReaderAzure;
use KernelModule\LogsModule\LoggerModule\LogReaderFile;

/**
 * Displays the logger logs
 *
 * @author     Martin Novák
 */
class DisplayPresenter extends BasePresenter {
	
	public function renderGeneral($from = NULL){
		$this->setView("default");
		$this->showMenu();
		$this->template->title = _("General Logs");
		$this->readLogs("log4phpAll", $from);
	}
	
	public function renderDebug($from = NULL){
		$this->setView("default");
		$this->showMenu();
		$this->template->title = _("Debug Logs");
		$this->readLogs("log4phpDebugOnly", $from);
	}
	
	public function renderErrors($from = NULL){
		$this->setView("default");
		$this->showMenu();
		$this->template->title = _("Error Logs");
		$this->readLogs("log4phpErrors", $from);
	}
	
	private function readLogs($target,$from){
		$result = NULL;
		if(AZURE){
			$result = LogReaderAzure::getLogsList($target,explode("§",$from));
			if(count($result)==50){
				$this->template->next = $result[49]["id"][0]."§".$result[49]["id"][1];
			}
			$this->template->logs = $result;
		} else {
			switch($target){
				case "log4phpAll":
					$target = "all";
					break;
				case "log4phpDebugOnly":
					$target = "debug-only";
					break;
				case "log4phpErrors":
					$target = "errors";
					break;
			}
			$result = LogReaderFile::getLogsList($target,explode("§",$from));
			if(count($result)==50){
				$this->template->next = $from+51;
			}
			$this->template->logs = $result;
		}
	}

}